package com.kele.order.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitMQConfig {

    private static final String QUEUE_NAME = "queue_order";
    private static final String EXCHANGE_NAME = "exchange_direct_order";
    private static final String BINDING_KEY = "order";

    @Bean(QUEUE_NAME)
    public Queue queueDeclare_order(){
        //return new Queue(QUEUE_NAME,true);
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    @Bean(EXCHANGE_NAME)
    public Exchange exchangeDeclare_order(){
        return ExchangeBuilder.directExchange(EXCHANGE_NAME).durable(true).build();
    }

    @Bean
    public Binding bindingDeclare_order(
            @Qualifier(QUEUE_NAME) Queue queue,
            @Qualifier(EXCHANGE_NAME) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(BINDING_KEY).noargs();
    }

}
